package com.tuananh.radnom.persist.imp.xml;

import java.util.ArrayList;

import com.ajexperience.utils.DeepCopyException;
import com.ajexperience.utils.DeepCopyUtil;
import com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
import com.tuananh.radnom.model.netpoller.Command;
import com.tuananh.radnom.model.netpoller.NetPoller;
import com.tuananh.radnom.model.netpoller.NetPollerConfiguration;
import com.tuananh.radnom.model.netpoller.NetPollerMap;
import com.tuananh.radnom.model.netservice.NetServiceConfiguration;
import com.tuananh.radnom.persist.AbstractPersitor;
import com.tuananh.radnom.persist.INetPollerDAO;


public class NetPollerXmlDAO extends XmlDAO implements INetPollerDAO {
	NetPollerConfiguration netPollerConfiguration;
	public NetPollerXmlDAO() {
		super(NetPollerConfiguration.path);
		configuration = XmlConfigHolder.netPollerConfig;
		try {
			savedConfiguration = (new DeepCopyUtil()).deepCopy(configuration);
		} catch (DeepCopyException e) {
			// TODO Auto-generated catch block
			savedConfiguration = new NetPollerConfiguration();
			e.printStackTrace();
		}
		netPollerConfiguration = (NetPollerConfiguration) configuration;
		
	}
	public ArrayList<NetPollerMap> getAll(){
		return netPollerConfiguration.getNetPoller();
	}
	public NetPoller getByName(String name) {
		// TODO Auto-generated method stub
		
		for (int i=0;i<netPollerConfiguration.getNetPoller().size();i++){
			if (netPollerConfiguration.getNetPoller().get(i).getName().equals(name)){
				return netPollerConfiguration.getNetPoller().get(i).getNetPoller();
			}
		}
		return null;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "NetPollerEvent";
	}

	public Command getCommandByName(String cmdName) {
		// TODO Auto-generated method stub
		for(Command command:netPollerConfiguration.getCommands()){
			if (command.getName().equals(cmdName)) return command;
		}
		return null;
	}
	
}
